<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
	<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
%>
<html>
<head>

<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/icon.css">
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/locale/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
$(function(){
	
	 $('#dg').datagrid({
         url:"<%=path%>/userAction/getUserDataGrid",
         //开启分页
         pagination : "true",
         //设置分页工具栏位置
         pagePosition : "bottom",
         //设置分页间隔
         pageList : [ 4, 8, 16 ],
         pageSize : 4,
         width : 630,
         //是否从服务器对数据进行排序
         //定义顶部工具栏的DataGrid面板
         //定义网格的标题
         toolbar : "#search",
         title : "用户管理",
         columns : [ [
         //定义列，这里有三列，每一列的都是一个对象，title为列标题，field为字段的名称
         {
             title : "",
             field : "ck",
             checkbox : true
         }, {
             title : "用户名",
             field : "username",
            	 width : 150,
     			align : "center",

         }, {
             title : "密码",
             field : "password",
         	width : 150,
			align : "center",
         }, {
             title : "状态",
             field : "status",
         	width : 150,
			align : "center",
             formatter: function(value,row,index){
 				if (value=="0"){
 					return "正常";
 				} else if(value=="1"){
 					return "<font color='red'>冻结</font>";
 				}
 			}
             
         },{
				title:"操作",
				field:"sid",
				width : 150,
				align : "center",
				  formatter : function(value, row, index) {
					  return '<a href="<%=path%>/userAction/userDescByAdmin?userId='+row["id"]+'">查看</a> <a onclick="del('+row["id"]+')"">删除</a>';  
	                }
			}] ]

     });
	
})


		//搜素
		function doSearch(){
			var username=$("#username").val();
				$('#dg').datagrid({
                    //queryParams方法在请求远程数据的时候发送额外的参数,参数一定要是json格式的对象，而表单序列化后是数组对象。需要将数组对象转为json格式的对象
                    queryParams: {
                        "username":username
                    }
                });
		}
		
		//删除某个用户
		function del(userid){
			
			 $.messager.confirm('提示','您确定删除该用户?',function(r){   
				 if(r){
						$.ajax({
							 url:'<%=path%>/userAction/del',
							 type:'POST', 
							 data:{
								 userId:userid,
							    },
							 success:function(data,textStatus,jqXHR){
								 $.messager.confirm('提示','删除成功',function(r){    
									 $('#dg').datagrid('reload',{
										});
									}); 
							    }
							
						})
				 }
				
				}); 
			
	
			
			
		}

</script>



<body class="easyui-layout" >   

    <table id="dg"></table>
   
   	<div id="search" style="padding: 3px">
		<span>用户名:</span> <input id="username"
			style="line-height: 20px; width:60px;border: 1px solid #ccc"> 
			<a href="#" class="easyui-linkbutton" style="margin-left: 75px;" data-options="iconCls:'icon-search'" plain="true" onclick="doSearch();">搜索</a>
	</div>
   
</body>  

</html>